<<<<<<< HEAD
<<<<<<< HEAD
<template>
  <!-- <van-nav-bar title="标题" left-text="返回" left-arrow @click-left="onClickLeft" /> -->
  <div class="box">
    <div class="kong" v-if="cart.length == 0">购物车为空</div>
    <div class="box2" v-else>
      <div class="cards" v-for="item in cart" :key="item.shop_spu_id">
        <van-swipe-cell>
          <div class="card-box">
            <input type="checkbox" @click="upChecked(item.shop_spu_id)" :checked="item.checked" />
            <!-- <div class="card">
              <img :src="item.swiper_info.img_list[0]" alt="" />
              <div class="card-info">
                <p>{{ item.drug_desc.name }}</p>
                <p style="color: red; font-weight: 600">￥{{ item.goods_info.price }}</p>
              </div>
            </div> -->
            <div class="operate">
              <button @click="add(item.shop_spu_id)">+</button>
              <p>{{ item.count }}</p>
              <button @click="sub(item.shop_spu_id)">-</button>
            </div>
          </div>
          <template #right>
            <van-button
              square
              text="删除"
              type="danger"
              class="delete-button"
              @click="deleteCart(item.shop_spu_id)"
            />
          </template>
        </van-swipe-cell>
      </div>
    </div>
    <van-submit-bar
      :price="allPrices"
      button-text="去结算"
      v-show="cart.length != 0"
      @submit="goOrder"
    >
      <van-checkbox v-model="checked" @click="allChecked">全选</van-checkbox>
=======
<style lang="scss" scoped>
.cart-item {
  width: 100%;
  background-color: #fff;
  margin-top: 0.5rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
}
.chanked {
  width: 100%;
  display: flex;
  height: 3rem;
  position: relative;
}
.cart-i {
  width: 100%;
  display: flex;
  // background-color: aqua;
  border: 1px solid #f6f6f6;
  img {
    width: 80px;
  }
  div:first-child {
    width: 2rem;
    // background-color: red;
  }
  div:last-child {
    flex: 0.5rem;
  }
  div {
    margin-top: 0.3rem;
    margin: 0.5rem;
  }
}
.cart-i:last-child {
  border-bottom: none;
}
.cart-i-right {
  p {
    font-size: 0.8rem;
    color: #626262;
    margin-top: 0.3rem;

    button {
      height: 1rem;
      line-height: 1rem;
      background-color: #4dd676;
      border: none;
      // padding: 0 .2rem;
      color: #fff;
      border-radius: 15%;
      margin-right: 0.2rem;
    }
  }
}
</style>
<template>
  <div
    style="
      background-color: #f2f2f2;
      width: 100wv;
      height: 100vh;
      overflow: auto;
      padding-bottom: 5rem;
    "
  >
    <van-nav-bar title="购物车" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div style="width: 97%">
      <div v-for="(item, index) in cart" :key="index" class="cart-item">
        <div class="chanked" @click="cartChanked(item)">
          <van-checkbox
            v-model="item.checked"
            style="position: absolute; top: 1rem; left: 0.6rem; font-size: 1rem"
            icon-size="1.2rem"
            checked-color="#ff6134"
            >{{ item.title }}</van-checkbox
          >
        </div>
        <div>
          <div
            v-for="(i, index) in item.goods"
            :key="index"
            class="cart-i"
            @click="allchanked(i, item)"
          >
            <div style="display: flex; align-items: center">
              <van-checkbox
                v-model="i.checked"
                icon-size="1rem"
                checked-color="#ff6134"
              ></van-checkbox>
            </div>
            <div style="flex: 0.3">
              <img :src="i.image" alt="" />
            </div>
            <div class="cart-i-right">
              <p>
                <button>{{ i.tag }}</button>{{ i.title }}
              </p>
              <select
                style="
                  background-color: #f2f2f2;
                  border: none;
                  color: #c1c1c1;
                  width: 80%;
                  padding: 0.1rem 0;
                  margin-top: 0.8rem;
                "
              >
                <option>{{ i.title }}</option>
                <option>200丸/瓶</option>
                <option>0.29克*/54片</option>
              </select>
              <div style="display: flex; margin-top: 0.5rem; width: 100%; align-items: center">
                <p style="flex: 0.9; color: red">￥{{ i.price }}</p>
                <van-stepper v-model="i.num" input-width="1.5rem" button-size="1.5rem" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <van-empty description="暂无任何数据" v-if="!cart.length" />

    <van-submit-bar
      button-color="#ff6700"
      :price="toAllPrice * 100"
      button-text="提交订单"
      @submit="onSubmit"
    >
      <div><van-checkbox @change="onClickCheckAll" v-model="allchecked">全选</van-checkbox></div>
      <template #tip> 你的收货地址不支持配送, <span @click="onClickLink">修改地址</span> </template>
>>>>>>> 1f89f8ca1715d7b56743d4d44cb055c67fd17ba2
    </van-submit-bar>
  </div>
</template>

<script setup lang="ts">
<<<<<<< HEAD
import { ref } from 'vue'
import { useCounterStore } from '../../api/pinia'
import { zhDebounce } from '../../utils/fang'
import { useRouter } from 'vue-router'
const router = useRouter()
//去结算
const goOrder = zhDebounce(() => {
  router.push('/order')
}, 1000)

// const onClickLeft = () => history.back();
const counterStore = useCounterStore()
const cart = ref('')
const checked = ref()
const allPrices = ref()
const getData = () => {
  cart.value = JSON.parse(localStorage.getItem('cart')) || []
  checked.value = counterStore.allCheckeds
  allPrices.value = counterStore.allPrices
  localStorage.setItem('allPrices', JSON.stringify(allPrices.value))
  console.log(counterStore.allPrices)
}
getData()
//选中的数量

// 单选选中
// const upChecked = (index: number) => {
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData();
// };



// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

// const upChecked = (index:number)=>{
//   counterStore.Dchecked(index);
//   counterStore.checkAllSelectedStatus();
//   counterStore.allPrice();
//   getData()
// }

const upChecked = (index:number)=>{
  counterStore.Dchecked(index);
  counterStore.checkAllSelectedStatus();
  counterStore.allPrice();
  getData()
}

// 全选
const allChecked = () => {
  counterStore.allChecked()
  counterStore.allPrice()
  getData()
}

// 加
const add = (index) => {
  counterStore.addCount(index)
  counterStore.allPrice()
  getData()
}

// 减
// const sub = (index) => {
//   counterStore.subCount(index);
//   counterStore.allPrice();
//   getData();
// };

const sub = (index) => {
  counterStore.subCount(index)
  counterStore.allPrice()
  getData()
}

// 删除
// const deleteCart = (index) => {
//   counterStore.deleteCart(index);
//   counterStore.allPrice();
//   getData();
// };

const deleteCart = (index) => {
  counterStore.deleteCart(index)
  counterStore.allPrice()
  getData()
}
</script>
<style scoped>
.box {
  width: 100%;
  height: 100vh;
}

.kong {
  width: 100%;
  height: 10%;
  text-align: center;
  line-height: 10vh;
  font-size: 20px;
  color: #ccc;
}

.card {
  width: 100%;
  height: 100px;
  display: flex;
  padding: 10px;
}

.card img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 25px;
}

.cards {
  width: 100%;
  height: 100px;
  display: flex;
  flex-direction: row;
}

.card-box {
  width: 100%;
  height: 100px;
  display: flex;
  flex-direction: row;
}

.box2 {
  width: 100%;
  padding: 5px;
  background: white;
}

.submit {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100px;
}

.card-info {
  width: 50%;
  line-height: 30px;
}

.operate {
  width: 20%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.operate button {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #ccc;
  background: #ccc;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.van-swipe-cell {
  width: 100%;
}

.van-button {
  height: 100%;
  margin-left: 20px;
}
</style>
=======
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
const onClickLeft = () => history.back()
var cart = ref(JSON.parse(localStorage.getItem('cartData') as string) || [])
const router = useRouter()
const onClickLink = () => showToast('修改地址')
const allchecked = ref(JSON.parse(localStorage.getItem('allchecked') as string) || false)
const onClickCheckAll = (value: any) => {
  cart.value.forEach((item: any) => {
    item.checked = value
    item.goods.forEach((item: any) => {
      item.checked = value
    })
  })
  localStorage.setItem('cartData', JSON.stringify(cart.value))
  localStorage.setItem('allchecked', JSON.stringify(allchecked.value))
}
const cartChanked = (item: any) => {
  console.log(item)
  item.checked = !item.checked
  if (item.checked) {
    item.goods.forEach((item: any) => {
      item.checked = true
    })
  } else {
    item.goods.forEach((item: any) => {
      item.checked = false
    })
  }
}
// 计算总价
const toAllPrice = computed(() => {
  var zprice = 0
  cart.value.forEach((item: any) => {
    item.goods.forEach((item: any) => {
      if (item.checked) {
        zprice += item.price * item.num
      }
    })
  })
  return zprice
})
const allchanked = (item: any, ind: any) => {
  item.checked = !item.checked
  var num = 0
  ind.goods.forEach((item1: any) => {
    if (!item1.checked) {
      ind.checked = false
    } else if (item1.checked) {
      num++
      if (num == ind.goods.length) {
        ind.checked = true
      }
    }
  })
  console.log(ind)
}
const onSubmit = () => {
  console.log(cart.value)
  var data: any = []
  cart.value.forEach((item: any) => {
    item.goods.forEach((i: any) => {
      if (i.checked) {
        data.push({ title: i.vendor, goods: [i] })
      }
    })
  })
  const mergedArr = Object.values(
    data.reduce((acc:any, current:any) => {
      const key = current.title
      if (!acc[key]) {
        acc[key] = { ...current }
      } else {
        acc[key].goods.push(current.goods[0])
      }
      return acc
    }, {}),
  )

  router.push({
    path: '/order',
    query: { data: JSON.stringify(mergedArr) },
  })
}
</script>

<style lang="scss" scoped></style>
>>>>>>> 1f89f8ca1715d7b56743d4d44cb055c67fd17ba2
=======
<template>
  <div class="zong">
    <!-- 头部 -->
    <div class="dingbu">商城</div>
    <!-- 搜索框 -->
    <van-sticky>
      <div class="sousuok">
        <div class="sousuok2">
          <input v-model="input" class="input" />
          <el-button class="sousuo">搜索</el-button>
          <van-icon name="service-o" class="tupian" size="25px" />
        </div>
        <div class="tz">
          <van-notice-bar background="none" color="#000" :scrollable="false">
            <van-swipe vertical class="notice-swipe" :autoplay="3000" :touchable="false" :show-indicators="false">
              <van-swipe-item v-for="(item, index) in gundong" :key="index">{{ item }}</van-swipe-item>
            </van-swipe>
          </van-notice-bar>
        </div>
      </div>
    </van-sticky>
    <!--导航菜单 -->
    <div class="caidan">
      <div v-for="(item, index) in caidan" :key="index" class="caidan2">
        <div><img :src="item.image" alt=""></div>
        <div>{{ item.name }}</div>
      </div>
    </div>
    <!-- 问诊开药 -->
    <div class="kaiyao">
      <div class="zuo">
        <img src="../../img/9acf1989-5545-4dd7-8b5b-e094be5d3289.png" alt="">
        <span class="open">问诊开药</span>
        <p class="huanze">适用于常见病、病情稳定的慢性病复诊患者</p>
      </div>
      <div>
        <button class="you">立即问诊</button>
      </div>
    </div>
    <!-- 健康护肤 -->
    <div class="hufu">
      <div v-for="(item, index) in hufu" :key="index">
        <div>
          <a :href="item.jump_url">
            <img :src="item.img_url" alt="">
          </a>
        </div>
      </div>
    </div>
    <!-- 健康体检 -->
    <div class="tijian">
      <div v-for="(item, index) in tijian" :key="index">
        <div>
          <a :href="item.jump_url">
            <img :src="item.img_url" alt="">
          </a>
        </div>
      </div>

    </div>
    <!-- 列表 -->
    <div class="list">
      <div v-for="(item, index) in list" :key="index" class="list2"
        @click="$router.push(`/cartdetail/${item.shop_spu_id}`,)">
        <div>
          <img :src="item.image" alt="">
        </div>
        <div class="list3">
          <p><span class="list3-1">{{ item.tag }}</span><span>{{ item.title }}</span></p>
          <p style="color: #aaaaaa;">{{ item.subtitle }}</p>
          <p style="color:red;">￥{{ item.price }}</p>
        </div>
      </div>
    </div>

    <van-icon name="cart-o" class="icon2" size="26px" @click="shop"
      :badge="cartItems === null ? 0 : cartItems.length" />
  </div>
</template>

<script lang="ts" setup>
import { getcaidan, gethufu, getlist, getsousuo, gettijian } from '../../request/http';
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const cartItems = ref([]);
onMounted(() => {
  const savedCart = JSON.parse(localStorage.getItem('cart')) || null;
  cartItems.value = savedCart;
  console.log(cartItems.value, '长度')
});
const input = ref('')
// 搜索上下滚动
const gundong = ref<any>()
getsousuo().then((res) => {
  gundong.value = res.data.data.hot_search_key_words
  console.log(gundong.value, 2);
})
// 导航菜单
const caidan = ref<any>()
getcaidan().then((res) => {
  caidan.value = res.data.data.goods_category
  console.log(caidan.value, 1);
})
// 健康护肤
const hufu = ref<any>()
gethufu().then((res) => {
  hufu.value = res.data.data.recommend_big_cards
  console.log(hufu.value, 3)
})
// 健康体检
const tijian = ref<any>()
gettijian().then((res) => {
  tijian.value = res.data.data.recommend_small_cards
  console.log(tijian.value, 4)
})
// 列表
const list = ref<any>()
getlist().then((res) => {
  list.value = res.data.data.content_list
  console.log(list.value, 5)
})
const shop = () => {
  router.push('/Shopping')
}
</script>

<style lang="scss" scoped>
.zong {
  background-color: #f7f7f7;
  width: 100%;
  height: 100%;
}

// 顶部
.dingbu {
  text-align: center;
  height: 30px;
  line-height: 30px;
  font-size: 14px;
  background-color: #8ed8b3;
}

.huanze {
  color: #9999;
  font-size: 11px;
}

.tupian {
  margin-right: 10px;
  margin-top: 5px;
}

.open {
  font-weight: 1000px;
  font-size: 15px;
}

// 搜索框
.sousuok {
  height: 60px;
  width: 100%;
  background-color: #8ed8b3;
  line-height: 60px;

  .sousuok2 {
    width: 85%;
    height: 50px;
    position: absolute;
    margin-left: 10px;

    .input {
      height: 32px;
      width: 90%;
      position: relative;
      border-radius: 50px;
      border: 1px solid #2ebb89;
    }

    .sousuo {
      position: absolute;
      right: 10%;
      top: 28%;
      border-radius: 50px;
      background-color: #2ebb89;
      color: #fff;
      width: 70px;
      height: 30px;
      line-height: 30px;
      text-align: center;
    }

    .tupian {
      position: absolute;
      top: 10px;
      right: -30px;
      color: #fff;

    }
  }

  .tz {
    margin-left: 10px;
    width: 50%;
    color: #a7a7a7;

    .notice-swipe {
      margin-top: 30px;
      height: 30px;
      line-height: 20px;
      color: #a7a7a7;
    }
  }
}

// 导航菜单
.caidan {
  background: linear-gradient(to bottom, #aae1c5, #fdfdfd);
  width: 100%;
  height: 150px;

  .caidan2 {
    width: 20%;
    height: 80px;
    text-align: center;
    font-size: 12px;
    float: left;

    img {
      width: 50px;
      height: 50px;
    }
  }
}

// 问诊开药
.kaiyao {
  width: 90%;
  margin-left: 5%;
  height: 50px;
  background: linear-gradient(to bottom, #dcf3e7, #ffffff);
  display: flex;

  .zuo {
    font-weight: normal;
  }

  .you {
    border: 0;
    width: 70px;
    height: 22px;
    border-radius: 10px;
    margin-top: 20px;
    background-color: #39d167;
    color: #fff;
    margin-left: 50px;
  }
}

// 健康护肤
.hufu {
  width: 100%;
  height: 100%;
  display: flex;
  margin-top: 10px;
  margin-bottom: 10px;

  img {
    width: 98%;
    height: 100%;
    margin-right: 1%;
  }
}

// 健康体检
.tijian {
  display: flex;
  width: 100%;
  height: 100%;

  img {
    width: 98%;
    height: 100%;
  }
}

// 列表
.list {
  width: 100%;
  height: 1588px;
  column-count: 2;

  .list2 {
    margin-top: 4%;
    background-color: #fff;
    break-inside: avoid;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .list3 {
    width: 100%;
    height: 100px;
    font-size: 15px;
    break-inside: avoid;

    .list3-1 {
      background-color: #39d167;
      color: #fff;
      width: 23px;

    }
  }
}

//固定定位
.icon2 {
  width: 40px;
  height: 40px;
  background: orange;
  border-radius: 50%;
  position: fixed;
  bottom: 70px;
  right: 14px;
  text-align: center;
  line-height: 40px;
  color: #fff
}
</style>
>>>>>>> refs/remotes/origin/master
